import { Button,Label,Node, RichText } from "cc";
import BaseApp from "../../base/BaseApp";
import BaseView from "../../base/BaseView";

export enum ComfirmType {
	ConfirmAndCancel = 1, 
    Confirm = 2, 
    Close   = 3,  
}

export default class ComfrimView extends BaseView {
	private _data: any =null;

	get url():string{return "common:comfirmView"}

	constructor(data:any){
		super();
		this._data = data;
	}

	onLoad(){
		const btnComfirm:Node= this.node.getChildByPath("content/btn_comfirm");

		btnComfirm.on("click", this.onBtnClickEvent2, this);
		const btnCancel:Node= this.node.getChildByPath("content/btn_cancel");

		btnCancel.on("click", this.onBtnClickEvent2, this);
		this.node.getChildByPath("content/rt_content").getComponent(RichText).string = this._data.string;
		this.node.getChildByPath("content/label_title").getComponent(Label).string = this._data.title;
		if(this._data.frameType==2){
			btnCancel.active =false;
			const pos = btnComfirm.getPosition();

			pos.x = 0 ;
			btnComfirm.setPosition(pos);
		}else if(this._data.frameType==4){
			btnComfirm.active =false;
			const pos = btnCancel.getPosition();

			pos.x = 0 ;
			btnCancel.setPosition(pos);
		}

		this.setMutexMode(1);
	}

	onBtnClickEvent2(btn:Button):void{
		if(btn.node.name == "btn_comfirm"){
			if(this._data.comfirmCall!=null){
				this._data.comfirmCall.call();
			}
		}else if(this._data.cancelCall!=null){
			this._data.cancelCall.call();
		}

		BaseApp.instance().closeViewByName(this.node.name);
	}
}